package com.haierp.controller;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.common.collect.Sets;
import com.haierp.mapper.ShippingOrderMapper;
import com.haierp.mapper.ShippingTrackLBMapper;
import com.haierp.mapper.ShippingTrackMapper;
import com.haierp.mapper.ShippingTrackPxMapper;
import com.haierp.mapper.ShippingTrackYuntongMapper;
import com.haierp.model.ShippingOrder;
import com.haierp.model.ShippingTrack;
import com.haierp.model.ShippingTrackLB;
import com.haierp.model.ShippingTrackPx;
import com.haierp.model.ShippingTrackYuntong;
import com.haierp.service.IShippingOrderService;
import com.haierp.service.IShippingTrackPxService;
import com.haierp.service.IShippingTrackService;
import com.haierp.service.logistics.IHaihuService;
import com.haierp.util.DateUtil;
import com.haierp.util.ExpressUtil;
import com.haierp.util.MapUtil;
import com.wangzhixuan.commons.base.BaseController;

import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/tpl")
public class ThirdPartyLogisticsController extends BaseController {
	@Autowired
	private IShippingOrderService shippingOrderService;
	@Autowired
	private ShippingTrackMapper shippingTrackMapper;
	@Autowired
	private ShippingTrackYuntongMapper shippingTrackYuntongMapper;
	@Autowired
	private ShippingOrderMapper shippingOrderMapper;
	@Autowired
	private IShippingTrackService shippingTrackService;
	@Autowired
	private ShippingTrackLBMapper shippingTrackLBMapper;
	@Autowired
	private ShippingTrackPxMapper shippingTrackPxMapper;
	@Autowired
	private IShippingTrackPxService shippingTrackPxService;
	
	
	/**
	 * 邮客p2 回调
	 */
	@RequestMapping("/youkeP2CallBack")
	@ResponseBody
	public Object youkeP2CallBack(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			InputStream in = request.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String jsonStr = br.readLine();
			
			JSONObject jsonObject = JSONObject.fromObject(jsonStr);
			Map<String, Object> parameMap = (Map<String, Object>) JSONObject.toBean(jsonObject, Map.class);
			MorphDynaBean parameMorphDynaBean = (MorphDynaBean)parameMap.get("param");
			String shippingNo = (String)parameMorphDynaBean.get("oversea_express_no");	//包裹号
			Integer status = (Integer)parameMorphDynaBean.get("status");				//包裹状态
			String tplPkgStatus = null;
			switch(status) {
				case 0:
					tplPkgStatus = "未预报已入库";
					break;
				case 1:
					tplPkgStatus = "预报的未入库";
					break;
				case 2:
					tplPkgStatus = "已预报已入库";
					break;
				case 3:
					tplPkgStatus = "入库异常";
					break;
			}
			
			if(shippingNo != null ) {
				ShippingOrder shippingOrder = new ShippingOrder();
				shippingOrder.setShippingNo(shippingNo);
				ShippingOrder selShippingOrder = shippingOrderService.selectOne(shippingOrder);
				if(selShippingOrder != null) {
					selShippingOrder.setTplPkgStatus(tplPkgStatus);
					selShippingOrder.setGmtModify(new Date());
					shippingOrderService.updateSelectiveById(selShippingOrder);
				}
			}
			
			br.close();
			in.close();
			
			result.put("code", 0);
			result.put("message", "");
		} catch (Exception e) {
			result.put("code", 1);
			result.put("message", "邮客P2回调异常");
			logger.error("邮客P2回调异常：", e);
		}
		return result;
	}
	
	/**
	 * 邮客p4 回调
	 */
	@RequestMapping("/youkeP4CallBack")
	@ResponseBody
	public Object youkeP4CallBack(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			InputStream in = request.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String jsonStr = br.readLine();

			JSONObject jsonObject = JSONObject.fromObject(jsonStr);
			JSONObject param = jsonObject.getJSONObject("param");
			
			String logisticNo = param.getString("transfer_id");
			Integer status = param.getInt("status");
			ShippingTrack shippingTrack = new ShippingTrack();
			shippingTrack.setLogisticNo(logisticNo);
			shippingTrack.setStatus(status);
			ShippingTrack selShippingTrack = shippingTrackMapper.selectOne(shippingTrack);
			
			ShippingOrder orderShipping = new ShippingOrder();
			orderShipping.setLogisticNo(logisticNo);
			ShippingOrder selShippingOrder = shippingOrderMapper.selectOne(orderShipping);
			
			if(status == 0) {
				shippingTrack.setInfo("未出库");
			} else if(status == 1) {
				shippingTrack.setInfo("发往国内");
			} else if(status == 2) {
				shippingTrack.setInfo("递交航空公司");
			} else if(status == 3) {
				shippingTrack.setInfo("抵达国内");
			} else if(status == 4) {
				shippingTrack.setInfo("已转国内快递");
			} else if (status == 5) {
				shippingTrack.setInfo("用户已签收");
				if (selShippingOrder != null) {
					selShippingOrder.setStatus(2);
					shippingOrderService.updateById(selShippingOrder);
				}
				
			}
			
			shippingTrack.setShippingNo(param.getString("customer_ref_no"));
			if(param.has("receive_time")) {
				shippingTrack.setReceiveTime(DateUtil.convertStr2Date(param.getString("receive_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("oversea_in_time")) {
				shippingTrack.setOverseaInTime(DateUtil.convertStr2Date(param.getString("oversea_in_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("oversea_out_time")) {
				if (StringUtils.isNotBlank(logisticNo) && logisticNo!=null) {
					EntityWrapper<ShippingOrder> entityWrapper = new EntityWrapper<ShippingOrder>();
					entityWrapper.where("logistic_no={0}", logisticNo);
					ShippingOrder one = shippingOrderService.selectOne(entityWrapper);
					if (one != null) {
						one.setActionTime(DateUtil.convertStr2Date(param.getString("oversea_out_time"), DateUtil.DATE_PARTEN));
						shippingOrderService.updateSelectiveById(one);
					}

				}
				shippingTrack.setOverseaOutTime(DateUtil.convertStr2Date(param.getString("oversea_out_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("oversea_on_transfer_time")) {
				shippingTrack.setOverseaOnTransferTime(DateUtil.convertStr2Date(param.getString("oversea_on_transfer_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("inland_in_time")) {
				shippingTrack.setInlandInTime(DateUtil.convertStr2Date(param.getString("inland_in_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("inland_out_time")) {
				shippingTrack.setInlandOutTime(DateUtil.convertStr2Date(param.getString("inland_out_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("buyer_sign_time")) {
				shippingTrack.setBuyerSignTime(DateUtil.convertStr2Date(param.getString("buyer_sign_time"), DateUtil.DATE_PARTEN));
			}
			if(param.has("inland_express_id")) {
				shippingTrack.setInlandExpressId(param.getString("inland_express_id"));
			}
			if(param.has("inland_express_no")) {
				shippingTrack.setInlandExpressNo(param.getString("inland_express_no"));
			}
			if(param.has("weight")) {
				shippingTrack.setWeight(param.getDouble("weight"));
			}
			if(param.has("volume")) {
				shippingTrack.setVolume(param.getString("volume"));
			}
			if(param.has("totalfee")) {
				shippingTrack.setTotalfee(param.getDouble("totalfee"));
			}
			if(param.has("air_take_off")) {
				shippingTrack.setAirTakeOff(param.getString("air_take_off"));
			}
			if(param.has("airlines")) {
				shippingTrack.setAirlines(param.getString("airlines"));
			}
			if(param.has("flight")) {
				shippingTrack.setFlight(param.getString("flight"));
			}
			if(param.has("master_waybill_no")) {
				shippingTrack.setMasterWaybillNo(param.getString("master_waybill_no"));
			}
			if(param.has("api_order_type")) {
				shippingTrack.setApiOrderType(param.getString("api_order_type"));
			}
			
			if(selShippingTrack == null) {
				shippingTrack.setGmtCreate(new Date());
				shippingTrack.setGmtModify(new Date());
				shippingTrackMapper.insert(shippingTrack);
			} else {
				shippingTrack.setId(selShippingTrack.getId());
				shippingTrack.setGmtModify(new Date());
				shippingTrackMapper.updateSelectiveById(shippingTrack);
			}
			
			br.close();
			in.close();
			
			result.put("code", 0);
			result.put("message", "");
		} catch(Exception e) {
			result.put("code", 1);
			result.put("message", "邮客P4回调异常");
			logger.error("邮客P4回调异常：", e);
		}
		return result;
	}
	
	/**
	 * 运通回调(返回和请求参数严格按照文档格式来做)
	 */
	@RequestMapping("/yunTongCallBack")
	@ResponseBody
	public Object yunTongCallBack(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			InputStream in = request.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String jsonStr = br.readLine();
			// logger.error("运通回调参数test：", jsonStr);
			JSONObject param = JSONObject.fromObject(jsonStr);
			// logger.error("运通回调参数解析test：", param);
			String yundanCode = param.getString("Yundan_code");
			String statusName = param.getString("Status_name");
			Date statusDatetime = DateUtil.convertStr2Date(param.getString("Status_datetime").replace("T", " "),
					DateUtil.DATE_PARTEN);

			ShippingTrack shippingTrack = new ShippingTrack();
			shippingTrack.setShippingNo(yundanCode);
			shippingTrack.setLogisticNo(yundanCode);
			ShippingOrder orderList = null;
			if (StringUtils.isNotBlank(yundanCode)) {
				EntityWrapper<ShippingOrder> entityWrapper = new EntityWrapper<ShippingOrder>();
				entityWrapper.where("shipping_no={0}", yundanCode);
				orderList = shippingOrderService.selectOne(entityWrapper);
			}
			if (statusName.startsWith("离开")) {
				shippingTrack.setStatus(1);
				shippingTrack.setOverseaOutTime(statusDatetime);
				shippingTrack.setInfo("发往国内");
				//查询此发货单的物流轨迹
				EntityWrapper<ShippingTrack> selEntityWrapper = new EntityWrapper<ShippingTrack>();
				selEntityWrapper.where("shipping_no={0}", shippingTrack.getShippingNo());
				List<ShippingTrack> shippingReadyTracks = shippingTrackService.selectList(selEntityWrapper);
				Set<Integer> statusSet = Sets.newHashSet();
				if(shippingReadyTracks.size()>0) {
					shippingReadyTracks.forEach(item -> {
						statusSet.add(item.getStatus());
					});
				}
				if (orderList != null && !statusSet.contains(0)) {
					ShippingTrack updateone = new ShippingTrack();
					updateone.setGmtCreate(orderList.getGmtCreate());
					updateone.setGmtModify(orderList.getGmtCreate());
					updateone.setShippingNo(orderList.getShippingNo());
					updateone.setLogisticNo(orderList.getLogisticNo());
					updateone.setStatus(0);
					updateone.setInfo("未出库");
					shippingTrackMapper.insert(updateone);
				}
			} else if (statusName.startsWith("抵达")) {
				shippingTrack.setStatus(3);
				shippingTrack.setInlandInTime(statusDatetime);
				shippingTrack.setInfo("抵达国内");
			} else if (statusName.contains("已收货")) {
				shippingTrack.setStatus(4);
				shippingTrack.setInlandOutTime(statusDatetime);
				shippingTrack.setInfo("已转国内快递");
			}
			if (param.has("Trans_company_name")) {
				shippingTrack.setInlandExpressId(param.getString("Trans_company_name"));
			}
			if (param.has("Trans_code")) {
				shippingTrack.setInlandExpressNo(param.getString("Trans_code"));
			}

			if (shippingTrack.getStatus() != null) {
				ShippingTrack tjShippingTrack = new ShippingTrack();
				tjShippingTrack.setLogisticNo(shippingTrack.getLogisticNo());
				tjShippingTrack.setStatus(shippingTrack.getStatus());
				ShippingTrack selShippingTrack = shippingTrackMapper.selectOne(tjShippingTrack);
				if (selShippingTrack == null) {
					shippingTrack.setGmtCreate(new Date());
					shippingTrack.setGmtModify(new Date());
					shippingTrackMapper.insert(shippingTrack);
				}
			}

			ShippingTrackYuntong shippingTrackMiddle = new ShippingTrackYuntong();
			shippingTrackMiddle.setYundanCode(yundanCode);
			shippingTrackMiddle.setStatusName(statusName);
			ShippingTrackYuntong selShippingTrackMiddle = shippingTrackYuntongMapper.selectOne(shippingTrackMiddle);
			if (param.has("Key")) {
				shippingTrackMiddle.setKey(param.getString("Key"));
			}
			if (param.has("Action")) {
				shippingTrackMiddle.setAction(param.getString("Action"));
			}
			if (param.has("Status_datetime")) {
				shippingTrackMiddle.setStatusDatetime(statusDatetime);
			}
			if (param.has("Trans_company_name")) {
				shippingTrackMiddle.setTransCompanyName(param.getString("Trans_company_name"));
			}
			if (param.has("Trans_code")) {
				shippingTrackMiddle.setTransCode(param.getString("Trans_code"));
			}

			if (selShippingTrackMiddle == null) {
				shippingTrackMiddle.setGmtCreate(new Date());
				shippingTrackMiddle.setGmtModify(new Date());
				shippingTrackYuntongMapper.insert(shippingTrackMiddle);
			} else {
				shippingTrackMiddle.setId(selShippingTrackMiddle.getId());
				shippingTrackMiddle.setGmtModify(new Date());
				shippingTrackYuntongMapper.updateSelectiveById(shippingTrackMiddle);
			}
			
			br.close();
			in.close();
			
			result.put("Code", 100);
			result.put("Msg", "success");
		} catch(Exception e) {
			result.put("Code", 199);
			result.put("Msg", "运通快递回调异常");
			logger.error("运通快递回调异常：", e);
		}
		return result;
	}
	//测试抓取海狐推送物流状态
	@RequestMapping("/updateShippingTrack")
	public void shippingTrack(Long id) throws ParseException {
		logger.info("定时任务：更新写入国内物流运输轨迹===>Start");
		List<ShippingTrack> shippingTrackList = shippingTrackMapper.queryStatus();
		Map<String, String> categorymap = MapUtil.getCategoryKuaiDi();
		String inlandExpressId = "";
		for (int i = 0; i < shippingTrackList.size(); i++) {
		if (StringUtil.isNotBlank(shippingTrackList.get(i).getInlandExpressId())
					&& StringUtil.isNotBlank(shippingTrackList.get(i).getInlandExpressNo())
					&& !shippingTrackList.get(i).getInlandExpressId().contains("haihu")) {
				inlandExpressId = shippingTrackList.get(i).getInlandExpressId();
				if (categorymap.get(inlandExpressId) != null) {
					inlandExpressId = categorymap.get(inlandExpressId);
				}
				try {
					String info = "";
					if ("tiantian".equals(inlandExpressId) || "huitongkuaidi".equals(inlandExpressId)) {
						info = ExpressUtil.callbackLogisticsTrajectory(inlandExpressId,
								shippingTrackList.get(i).getInlandExpressNo());
					} else {
						info = ExpressUtil.getOrderTracesByJson(inlandExpressId,
								shippingTrackList.get(i).getInlandExpressNo());
					}
					Date date = null;
					if(StringUtils.isNotBlank(info)){
						JSONObject param = JSONObject.fromObject(info);
						if(param.containsKey("data")){
							JSONArray jsonArrayss = param.getJSONArray("data");
							for (int j = 0; j < jsonArrayss.size(); j++) {
								JSONObject object2 = jsonArrayss.getJSONObject(j);
								if(String.valueOf(object2.get("context")).contains("签收")){
									date = DateUtil.parseDate(object2.getString("time"));
								}
							}
						}else{
							String  one = (String) param.get("param");
							if(one != null){
								JSONArray jsonArrayss = param.getJSONArray("param");
								for (int j = 0; j < jsonArrayss.size(); j++) {
									JSONObject object2 = jsonArrayss.getJSONObject(j);
									if(String.valueOf(object2.get("AcceptStation")).contains("签收")){
										date = DateUtil.parseDate(object2.getString("AcceptTime"));
									}
								}
							}

						}
					}
					if(date != null){
						ShippingTrack  one = shippingTrackList.get(i);
						one.setGmtModify(date);
						shippingTrackService.updateSelectiveById(one);
						System.out.println(one.getShippingNo());
					}
					if (info.contains("签收")) {
						shippingOrderMapper.updateStatusByShippingNo(shippingTrackList.get(i).getShippingNo());
					}
					shippingTrackMapper.updateInfo(info, shippingTrackList.get(i).getShippingNo());
					Thread.sleep(100);
				} catch (Exception e) {
					logger.error("抓取物流轨迹定时任务(非海狐)", e);
				}

			}
		}
		logger.info("定时任务：更新写入国内物流运输轨迹===>END");
	}
	/**
	 * 联邦回调
	 */
	@RequestMapping("/fedroadReturn")
	@ResponseBody
	public String fedroadReturn(HttpServletRequest request) {
		String  responseXml = "";
		try {
			String XmlParams = request.getParameter("XmlParams");	//参数内幕
			logger.info("联邦回调参数："+ XmlParams);
			if(StringUtils.isNotBlank(XmlParams)){
				Document doc = DocumentHelper.parseText(XmlParams);
				Element userOrder = doc.getRootElement();
				Element orderReturn = userOrder.element("Notify");
				String returnOrderValue = orderReturn.getText();
				if(returnOrderValue.equals("VerifyNotify")){
					Element paramReturn = userOrder.element("Parameters");
					Element orderNoParam = paramReturn.element("OrderNo");
					Element statusParam = paramReturn.element("Status");
					Element descripParam = paramReturn.element("Description");
					String orderNo = orderNoParam.getText();
					String status = statusParam.getText();
					String descripText = descripParam.getText();
					if(StringUtils.isNotBlank(orderNo)){
						logger.info("联邦回调任务：" + descripText);	
						ShippingTrackLB one = new ShippingTrackLB();
						one.setShipperOrderNo(orderNo);
						shippingTrackLBMapper.insert(one);
					}
				}
				responseXml = "<Root><Return>0</Return></Root>";
			}

		} catch (Exception e) {
			logger.info("联邦回调通知失败");	
			responseXml = "<Root><Return>通知失败</Return></Root>";
		}
		return responseXml;
	}

	/**
	 * 4PX回调
	 */
	@RequestMapping("/transRushCallBack")
	@ResponseBody
	public Object transRushCallBack(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			logger.error("4PX回调");
			Enumeration pNames=request.getParameterNames();
			while(pNames.hasMoreElements()){
			    String name=(String)pNames.nextElement();
			    String value=request.getParameter(name);
			    System.out.println(name + "=" + value);
			    JSONObject json = JSONObject.fromObject(name);
				JSONObject param = json.getJSONObject("data");
				String shippingNo = param.getString("ShipperOrderNo");
				EntityWrapper<ShippingOrder> entityWrapper = new EntityWrapper<>();
				entityWrapper.where("shipping_no={0}", shippingNo);
				ShippingOrder shippingOrder = shippingOrderService.selectOne(entityWrapper);
				if(shippingOrder != null) {
					JSONArray jsonArray = param.getJSONArray("TrackingList");
					ShippingTrack shippingTrack = new ShippingTrack();
					shippingTrack.setShippingNo(shippingNo);
					shippingTrack.setLogisticNo(shippingNo);
					//查询此发货单的物流轨迹
					EntityWrapper<ShippingTrack> selEntityWrapper = new EntityWrapper<ShippingTrack>();
					selEntityWrapper.where("shipping_no={0}", shippingNo);
					List<ShippingTrack> shippingReadyTracks = shippingTrackService.selectList(selEntityWrapper);
					Set<Integer> statusSet = Sets.newHashSet();
					if(shippingReadyTracks.size()>0) {
						shippingReadyTracks.forEach(item -> {
							statusSet.add(item.getStatus());
						});
					}

					for (int i = 0; i < jsonArray.size(); i++) {
						JSONObject jsonArrayDetail = jsonArray.getJSONObject(i);
						String trackCode = jsonArrayDetail.getString("TrackStatusCode");
						SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			            if(trackCode.equalsIgnoreCase("PU") && !statusSet.contains(0)) {
							shippingTrack.setStatus(0);
							shippingTrack.setInfo("未出库");
							statusSet.add(0);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						} else if(trackCode.equalsIgnoreCase("LO") && !statusSet.contains(1)) {
							shippingTrack.setStatus(1);
							shippingTrack.setOverseaOutTime(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setInfo("递交航空公司");
							statusSet.add(1);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						} else if(trackCode.equalsIgnoreCase("FT") && !statusSet.contains(2)) {
							shippingTrack.setStatus(2);
							shippingTrack.setOverseaOnTransferTime(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setInfo("发往国内");
							statusSet.add(2);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						} else if(trackCode.equalsIgnoreCase("CP") && !statusSet.contains(3)) {
							shippingTrack.setStatus(3);
							shippingTrack.setInlandInTime(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setInfo("抵达国内");
							statusSet.add(3);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						} else if(trackCode.equalsIgnoreCase("IS") && !statusSet.contains(4)) {
							shippingTrack.setStatus(4);
							shippingTrack.setInfo(jsonArrayDetail.getString("TrackContent"));
							statusSet.add(4);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						} else if(trackCode.equals("OK") && !statusSet.contains(5)) {
							shippingTrack.setStatus(5);
							shippingOrderService.updateStatusByShippingNo(shippingNo);
							shippingTrack.setBuyerSignTime(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setInfo("用户已签收");
							statusSet.add(5);
							shippingTrack.setGmtCreate(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrack.setGmtModify(date.parse(jsonArrayDetail.getString("TrackTime")));
							shippingTrackService.insertSelective(shippingTrack);
						}
					}
					ShippingTrackPx pxon = new ShippingTrackPx();
					pxon.setShipperOrderNo(shippingNo);
					pxon.setDeliveryNo(shippingNo);
					pxon.setTrackInfo(jsonArray.toString());
					if(jsonArray.toString().contains("AO")){
					pxon.setIsGet(1);
					}
					EntityWrapper<ShippingTrackPx> selEntityWrapperPx = new EntityWrapper<ShippingTrackPx>();
					selEntityWrapperPx.where("shipping_no={0}", shippingNo);
					ShippingTrackPx  pxMiddle = shippingTrackPxService.selectOne(selEntityWrapperPx);
					if(pxMiddle == null){
						pxon.setGmtCreate(new Date());
						pxon.setGmtModify(new Date());
						shippingTrackPxMapper.insert(pxon);
					}else{
						pxon.setId(pxMiddle.getId());
						pxon.setGmtModify(new Date());
						shippingTrackPxMapper.updateSelectiveById(pxon);
					}
				}

			}
			result.put("ResponseCode", "success");
			result.put("Message", "成功");
		} catch(Exception e) {
			result.put("ResponseCode", "fail");
			result.put("Message", "失败");
		}
		return result;
	}
}
